/**
 * @param {number[]} digits
 * @return {number[]}
 */
var plusOne = function(digits) {
    let i = digits.length-1;
    digits[i]++;
    let d = digits[i];
    while(d>=10){
        digits[i] = d%10;
        d = d - 9;
        if(i===0){
            digits.unshift(d);
            break;
        }
        i--;
        digits[i] = digits[i] + d;
        d = digits[i];
    }
    return digits;
};

console.log(plusOne([9]));
